import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', {
    state: () => ({
        isLoggedIn: false,
        user: {
            username: '',
            password: ''
        }
    }),
    actions: {
        login(username, password) {
            // 假设这里有一个简单的验证逻辑
            if (username === 'admin' && password === '123') {
                this.isLoggedIn = true;
                this.user.username = username;
                this.user.password = password;
            } else {
                alert('用户名或密码错误');
            }
        },
        logout() {
            this.isLoggedIn = false;
            this.user.username = '';
            this.user.password = '';
        }
    },
    persist: true // 启用持久化
});